﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using BusinessObjects.BO_GetObjects;
using LibraryO2S;

public partial class Controls_Settings : Pages_Base
{
    private DataTable objDT;
    protected void Page_Load(object sender, EventArgs e)
    {
        base.removeHGC(divMessage);
        if (!IsPostBack)
        {
            loadSettingGroups();
            if (Request["g_id"] != null)
                ddlSettingGroups.SelectedValue = Request["g_id"].ToString();
            loadData();
        }
    }
    private void loadData()
    {
        try
        {
            objDT = BO_Settings.SelectByGroupId(Convert.ToInt32(ddlSettingGroups.SelectedValue), 1);
            bindRepeater(rptData, objDT, divMessage);
        }
        catch (Exception ex) { throw ex; }
        finally { }
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        loadData();
    }
    protected void loadSettingGroups()
    {
        try
        {
            objDT = BO_SettingGroups.SelectAll(1);
            base.bindDDL(ddlSettingGroups, objDT, "FULL_SETTING_NAME", "SETTING_GROUP_ID");
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally { }
    }
    protected void rptData_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        try
        {
            if (e.CommandName.Equals("del"))
            {
                BO_Settings.Delete(Convert.ToInt32(e.CommandArgument));
                divMessage.InnerHtml = O2S_Message.Success("Thông Báo", "Xóa thành công .");
            }
            loadData();
        }
        catch (Exception ex)
        {
            divMessage.InnerHtml = O2S_Message.Error("Lỗi", "Phát hiện lỗi: <br />" + ex.Message);
        }
        finally { }
    }
    protected void btnNew_Click(object sender, EventArgs e)
    {
        Response.Redirect("default.aspx?module=settingnew");
    }
}